fix(core): use a queue to process events in event routes#18259
Merged
fix(core): use a queue to process events in event routes#18259
Conversation
Contributor
jlongster
commented
Mar 19, 2026
- Moves the /event route into it's own file
- Handle event processing more explicitly. Previously, it was doing await stream.writeSSE inside of a callback to Bus.subscribeAll. The Bus abstraction allows you to do await Bus.publish and it will actually wait for all listeners to finish processing, and since a listener is writing to SSE, it will block until the event is written to SSE
- However, that's a little strange, and is unpredictable because multiple paths could be publishing events through the bus. So it looks like it's writing events to SSE in order, but that's not actually guaranteed
- We aren't able to actually allow waiting when publishing events anymore. With the new sync system, it will handle emitting a lot of events internally
- We still should queue writing events to SSE. This PR does that by using effect's queue mechanism, pushing events as they come onto the queue and then sequentially processing them
36be614 to
f3ceefd
Compare
jlongster
commented
Mar 19, 2026
| for (const key of [def.type, "*"]) { | ||
| const match = state().subscriptions.get(key) | ||
| for (const sub of match ?? []) { | ||
| const match = [...(state().subscriptions.get(key) ?? [])] |
Contributor
Author
There was a problem hiding this comment.
Needed because there was a bug before where if you unsubscribed in a handler synchronously, it mutates this same array so it'll skip the next listener
bdb6673 to
25a2827
Compare
filipeandre
pushed a commit
to filipeandre/opencode
that referenced
this pull request
Mar 19, 2026
raf1hh
pushed a commit
to raf1hh/opencode
that referenced
this pull request
Mar 20, 2026
pengzha0
pushed a commit
to pengzha0/dwtcode
that referenced
this pull request
Mar 20, 2026
demostanis
pushed a commit
to demostanis/opencode
that referenced
this pull request
Mar 20, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.